package com.rfid.service.impl;

import java.lang.reflect.MalformedParameterizedTypeException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;

import com.rfid.domain.VO.HouseVO;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.system.mapper.SysUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.rfid.mapper.RfidHouseMapper;
import com.rfid.domain.RfidHouse;
import com.rfid.service.IRfidHouseService;

/**
 * 仓库信息Service业务层处理
 * 
 * @author ruoyi
 * @date 2022-12-28
 */
@Service
public class RfidHouseServiceImpl implements IRfidHouseService 
{
    @Autowired
    private RfidHouseMapper rfidHouseMapper;

    @Autowired
    private SysUserMapper userMapper;
    /**
     * 查询仓库信息
     * 
     * @param id 仓库信息主键
     * @return 仓库信息
     */
    @Override
    public RfidHouse selectRfidHouseById(Long id)
    {
        return rfidHouseMapper.selectRfidHouseById(id);
    }

    /**
     * 查询仓库信息列表
     *
     * @param rfidHouse 仓库信息
     * @return 仓库信息
     */
    @Override
    public List<RfidHouse> selectRfidHouseList(RfidHouse rfidHouse)
    {
        return rfidHouseMapper.selectRfidHouseList(rfidHouse);
    }

    @Override
    public List<HouseVO> selectHouseVOList(RfidHouse rfidHouse) {
        //仓库列表
        List<RfidHouse> Houses = rfidHouseMapper.selectRfidHouseList(rfidHouse);
        //用户列表
        List<SysUser> users=userMapper.selectUserNameList();

//        List<HouseVO> newList= Houses.stream().map(house -> {
//            users.stream().filter(user -> Objects.equals(house.getLeader(), user.getUserId())).forEach(user -> {
//                Houses.put("leaderName", user.getUserName());
//            });
//            return users;
//        }).collect(Collectors.toList());
        List<HouseVO> newList=new ArrayList<>();
        for (RfidHouse house: Houses){
            for (SysUser user: users){
                if (Objects.equals(house.getLeader(), user.getUserId())){
                    HouseVO houseVO=new HouseVO(house,user.getNickName());
                    newList.add(houseVO);
                }
            }

        }

        return newList;
    }

    /**
     * 新增仓库信息
     * 
     * @param rfidHouse 仓库信息
     * @return 结果
     */
    @Override
    public int insertRfidHouse(RfidHouse rfidHouse)
    {
        return rfidHouseMapper.insertRfidHouse(rfidHouse);
    }

    /**
     * 修改仓库信息
     * 
     * @param rfidHouse 仓库信息
     * @return 结果
     */
    @Override
    public int updateRfidHouse(RfidHouse rfidHouse)
    {
        return rfidHouseMapper.updateRfidHouse(rfidHouse);
    }

    /**
     * 批量删除仓库信息
     * 
     * @param ids 需要删除的仓库信息主键
     * @return 结果
     */
    @Override
    public int deleteRfidHouseByIds(Long[] ids)
    {
        return rfidHouseMapper.deleteRfidHouseByIds(ids);
    }

    /**
     * 删除仓库信息信息
     * 
     * @param id 仓库信息主键
     * @return 结果
     */
    @Override
    public int deleteRfidHouseById(Long id)
    {
        return rfidHouseMapper.deleteRfidHouseById(id);
    }
}
